package com.liws.helloThreadPools.utils;

/**
 * @author ：liweisheng
 * @date ：2021/12/26 15:05
 * @description：阶乘
 */
public class FactorialUtils {
    /**
     *
     *  求阶乘
     * @param num
     * @return
     */
    public static Long countFactorial(Long num){
        if (num < 1){
            throw new RuntimeException("num 不能小于1");
        }

        if (num == 1L){
            return num;
        }


        return num*countFactorial(--num);

    }

    /**
     *  求阶乘的和
     * @param num
     * @return
     */
    public static Long sumCountFactorial(Long num){

        Long sum=0L;
        for (Long j=1L;j<=num;j++){
            Long aLong = countFactorial(j);
            sum+=aLong;
        }
        return sum;
    }

}
